package com.guigu.tms.aggregation.controller;

import com.guigu.tms.aggregation.service.IOrderClassifyOrderService;
import com.guigu.tms.aggregation.service.IOrderService;
import com.guigu.tms.commons.aggregation.entity.Order;
import com.guigu.tms.commons.aggregation.entity.OrderClassifyOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 订单分类订单关联表 前端控制器
 * </p>
 *
 * @author wj
 * @since 2022-10-21
 */
@RestController
@RequestMapping("/orderClassifyOrder")
public class OrderClassifyOrderController {

    @Autowired
    IOrderClassifyOrderService iOrderClassifyOrderService;

    @Autowired
    IOrderService iOrderService;

    @GetMapping("/ShowOrderClassifyOrder")
    public List<OrderClassifyOrder> ShowOrderClassifyOrder(@RequestParam String tripsId,@RequestParam(value = "end", required = true) String end){
        List<OrderClassifyOrder> orderClassifyOrders = iOrderClassifyOrderService.ShowOrderClassifyOrder(tripsId);
        List<OrderClassifyOrder> classifyOrders=new ArrayList<>();
        for(int i=0;i<orderClassifyOrders.size();i++){
            String orderId = orderClassifyOrders.get(i).getOrderId();
            //System.out.println(orderId);
            int i1 = iOrderService.UpdateOrder(end, orderId);
            if(i1>0){
                classifyOrders.add(orderClassifyOrders.get(i));
            }
        }
        return orderClassifyOrders;
    }

}
